<!--会议室预定纪录-->
<template>
	<el-card>
		<el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
			<el-form-item class="form-button-right">
				<el-button v-auth="'chamber:chamber:save'" type="primary" @click="addOrUpdateHandle()">预定会议室</el-button>
			</el-form-item>

			<el-form-item label="会议室">
				<el-tree-select
					v-model="state.queryForm.pid"
					:data="chamberList"
					value-key="id"
					check-strictly
					clearable
					:render-after-expand="false"
					:props="{ value: 'id', label: 'name', children: 'children' }"
					placeholder="请选择"
				>
				</el-tree-select>
			</el-form-item>
			<el-form-item label="会议日期">
				<ElDatePicker
					v-model="state.queryForm.startDatetime"
					range-separator="To"
					type="daterange"
					start-placeholder="会议开始日期"
					end-placeholder="会议结束日期"
					value="yyyy-MM-dd HH:mm:ss"
				/>
			</el-form-item>
			<el-form-item label="会议状态">
				<el-tree-select
					v-model="state.queryForm.stateId"
					:data="stateList"
					value-key="id"
					check-strictly
					clearable
					:render-after-expand="false"
					:props="{ value: 'code', label: 'name', children: 'children' }"
					placeholder="会议室状态"
				>
				</el-tree-select>
			</el-form-item>
			<el-form-item>
				<KeyQuery v-model="state.queryForm.keyword" @getDataList="getDataList()" />
			</el-form-item>
		</el-form>

		<el-table v-loading="state.dataListLoading" :data="state.dataList" border style="width: 100%" @selection-change="selectionChangeHandle">
			<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
			<el-table-column prop="id" label="主键" header-align="center" align="center" v-if="false"></el-table-column>

			<el-table-column prop="name" label="会议名称" header-align="center" align="center"></el-table-column>
			<el-table-column prop="pid" label="会议室" header-align="center" align="center"></el-table-column>
			<el-table-column prop="startDatetime" label="会议开始时间" header-align="center" align="center"></el-table-column>
			<el-table-column prop="endDatetime" label="会议结束时间" header-align="center" align="center"></el-table-column>
			<el-table-column prop="remindId" label="会议状态" header-align="center" align="center"></el-table-column>
			<el-table-column prop="remindId" label="预定人员" header-align="center" align="center"></el-table-column>

			<el-table-column prop="remindId" label="预定时间" header-align="center" align="center"></el-table-column>

			<el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
				<template #default="scope">
					<el-button v-auth="'chamber:chamber:update'" type="primary" link @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
					<el-button v-auth="'chamber:chamber:delete'" type="primary" link @click="deleteBatchHandle(scope.row.id)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination
			:current-page="state.page"
			:page-sizes="state.pageSizes"
			:page-size="state.limit"
			:total="state.total"
			layout="total, sizes, prev, pager, next, jumper"
			@size-change="sizeChangeHandle"
			@current-change="currentChangeHandle"
		>
		</el-pagination>

		<!-- 弹窗, 新增 / 修改 -->
		<add-or-update ref="addOrUpdateRef" @refreshDataList="getDataList" :chamberList="chamberList"></add-or-update>
	</el-card>
</template>

<script setup lang="ts" name="ChamberLogIndex">
import { useCrud } from '@/hooks'
import { Ref, reactive, ref } from 'vue'
import { IHooksOptions } from '@/hooks/interface'
import { ElDatePicker } from 'element-plus'
import { findList } from '@/api/nb/chamber/chamber'
import { findListByDictId } from '@/api/nb/business/dictionaries_subset'

import AddOrUpdate from './plane/record-a-u.vue'

const state: IHooksOptions = reactive({
	dataListUrl: '/nb/chamber_log/page',
	deleteUrl: '/nb/chamber_log',
	queryForm: {}
})

const addOrUpdateRef = ref()
const addOrUpdateHandle = (id?: number) => {
	addOrUpdateRef.value.init(id)
}

const chamberList = ref()
// 获取 会议室
const getChamberList = () => {
	return findList({ params: {} }).then(res => {
		chamberList.value = res.data
		chamberList.value.unshift({ id: '', name: '请选择' })
	})
}
getChamberList()

//列表树
const stateList = ref()
const getDictList = (code: String, list: Ref) => {
	findListByDictId({ params: { code: code } }).then(res => {
		list.value = res.data
		list.value.unshift({ code: '', name: '请选择' })
	})
}
getDictList('HuiYiShiZhuangTai', stateList)

const { getDataList, selectionChangeHandle, sizeChangeHandle, currentChangeHandle, deleteBatchHandle } = useCrud(state)
</script>
